//
//  CreatNewProjectViewController.m
//  UEAssistant
//
//  Created by mac on 2017/7/17.
//  Copyright © 2017年 youyixinxi. All rights reserved.
//

#import "CreatNewProjectViewController.h"
#import "YHXCalendarView.h"
#import "TagsSecondView.h"
#import "YZSortCell.h"
#import "SelectLangViewController.h"
#import "UploadSetViewController.h"
#import <IQKeyboardManager.h>

extern NSString * const YZUpdateMenuTitleNote;
static NSString * const IDR = @"cell";

@interface CreatNewProjectViewController ()<UITableViewDataSource,UITableViewDelegate,UITextViewDelegate>{

    NSMutableArray              *_languageArray;
}



@property (nonatomic, strong) UILabel                                       *titleL;
@property (nonatomic, strong) UITableView       *tableView;
@property (nonatomic, strong) UIImageView       *headView;
@property (nonatomic, strong) UIView            *line;
@property (nonatomic, strong) UIButton          *buton;
@property (nonatomic, strong) UITextView        *productName;
@property (nonatomic, strong) UILabel           *teamName;
@property (nonatomic, strong) UILabel           *textViewPlaceholderLabel;
@property (nonatomic, strong) UILabel           *textViewPlaceholderLabelF;
@property (nonatomic, strong) UILabel           *SLabel;
@property (nonatomic, strong) UILabel           *TLabel;
@property (nonatomic, strong) UILabel           *time;
@property (nonatomic, strong) UITextView        *remarkTextView;
@property (nonatomic, strong) UIButton          *sureButton;
@property (nonatomic, strong) UILabel           *wordCount;
@property (nonatomic, strong) UIView            *coverView;
@property (nonatomic, strong) TagsSecondView    *tagsView;
@property (nonatomic, strong) NSMutableArray    *tags;
@property (nonatomic, strong) UITableView       *tableView_team;
@property (nonatomic, assign) NSInteger         selectedCol;// 记录选中的团队
@property (nonatomic, strong) NSMutableArray    *titleArray;
@property (nonatomic, strong) NSMutableArray    *idArray;
@property (nonatomic, strong) NSMutableArray    *faceArray;
@property (nonatomic, strong) UILabel                                             *tagLabel;
@property (nonatomic, strong) UILabel                                             *tagLabeltwo;
@property (nonatomic, strong) UILabel                                             *tagLabelThr;
@property (nonatomic, strong) UIButton          *deleteButton;
@property (nonatomic, copy)   NSString          *sourceKey;
@property (nonatomic, copy)   NSString          *targetKey;
@property (nonatomic, copy)   NSString          *ownerId;
@property (nonatomic, strong) NSMutableArray    *tagArray;


@end

@implementation CreatNewProjectViewController

- (void)viewWillAppear:(BOOL)animated{
    
    [_titleL setHidden:NO];
    [IQKeyboardManager sharedManager].enable = YES;
}

- (void)viewWillDisappear:(BOOL)animated{
    
    [_titleL setHidden:YES];
    [IQKeyboardManager sharedManager].enable = NO;

}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initlizeDataSource];
    [self initlizeUserface];
}

- (void)initlizeUserface{
    self.title =  @"新建项目";
    self.view.backgroundColor = [UIColor whiteColor];
//    _titleL = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 200, 20)];
//    _titleL.center = CGPointMake(self.view.center.x, 20);
//    _titleL.backgroundColor = [UIColor clearColor];
//    _titleL.text = @"新建项目";
//    _titleL.textAlignment = NSTextAlignmentCenter;
//    _titleL.textColor = [UIColor whiteColor];
//    [self.navigationController.navigationBar addSubview:_titleL];

    self.automaticallyAdjustsScrollViewInsets = NO; 
    [self.view addSubview:self.tableView];
    [self contentSizeToFitWithTextView:self.productName];
    [self.view addSubview:self.sureButton];
    [self.view addSubview:self.coverView];
    [self.view addSubview:self.tableView_team];
    [self.tableView_team registerClass:[YZSortCell class] forCellReuseIdentifier:IDR];
    _tagsView = [[TagsSecondView alloc]initWithFrame:CGRectMake(0, Screen_Height, Screen_Width, 0)];
    __weak typeof(_tags) weakTags = _tags;
    _tagsView.didSelectSectionHandler = ^(NSString *tag){
        if ([tag isEqualToString:@"重置"]) {
            [weakTags removeAllObjects];
        }
        if (![weakTags containsObject:tag] && ![tag isEqualToString:@"重置"]) {
            [weakTags addObject:[NSString stringWithFormat:@"  %@",tag]];
        }
    };
    [self.view addSubview:_tagsView];
    
}

- (void)initlizeDataSource{

    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(hideCoverCliced:) name:@"hideCover" object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(dismissTagsViewRespond) name:@"dismissTagsView" object:nil];
    _tags = [NSMutableArray array];
    _selectedCol = 0;
    
    NSString *mainBundleDirectory=[[NSBundle mainBundle] bundlePath];
    NSString *path=[mainBundleDirectory stringByAppendingPathComponent:@"alllanguage.json"];
    NSURL *url=[NSURL fileURLWithPath:path];
    NSData *data = [[NSData alloc] initWithContentsOfURL:url];
    NSLog(@"语言---%@",[self toArrayOrNSDictionary:data]);
    _languageArray = [NSMutableArray arrayWithArray:[self toArrayOrNSDictionary:data][@"result"]];
    _titleArray = [NSMutableArray array];
    _idArray = [NSMutableArray array];
    _faceArray = [NSMutableArray array];
    
    //这里开始请求团队数据
    [AvailableNetWorking postWithUrl:[userManager.urlCategate stringByAppendingString:checkTeamInfo_connector] params:nil successHandler:^(id responseObject) {
        
        NSLog(@"groups ============ %@",responseObject);
        if ([responseObject[@"code"] intValue] == 200) {
            NSArray *arr = responseObject[@"result"][@"myteam"];
            if (arr.count > 0) {
                [arr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                    
                    [_titleArray addObject:obj[@"teanName"]];
                    if ([[obj allKeys] containsObject:@"facePath"]) {
                        [_faceArray addObject:obj[@"facePath"]];
                    }else{
                        [_faceArray addObject:@"xxxxxxx"];
                    }
                    [_idArray addObject:[NSString stringWithFormat:@"%@",obj[@"teamId"]]];
                    
                }];
                NSLog(@"groppppppppppp == %@",_titleArray);
                self.teamName.text = _titleArray[0];
                [self.headView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",headImageViewOSS,_faceArray[0]]] placeholderImage:[UIImage imageNamed:@"user"]];

            }
            
        }else{
            NSLog(@"分组信息接收失败");
        }
    } falureHandler:^(NSError *error) {
        
        NSLog(@"分组信息接收失败");
    }];

    //获取标签键值对
    _tagArray = [NSMutableArray array];
    [AvailableNetWorking postWithUrl:transLabels_connector params:@{} successHandler:^(id responseObject) {
        
        NSLog(@"tags == %@",responseObject);
        if ([responseObject[@"code"] intValue] == 200) {
            NSArray * arr = responseObject[@"result"];
            [arr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                [_tagArray addObject:obj];
            }];
        }
    } falureHandler:^(NSError *error) {
        
    }];

}

#pragma mark -- UITableViewDataSource,UITableViewDelegate

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

    if (tableView == self.tableView) {
        
        return 3;

    }else{
    
        return 1;
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    if (tableView == self.tableView) {
        
        if (section == 0) {
            return 3;
        }
        else if (section == 1){
            
            return 2;
        }
        else{
            
            return 1;
        }

    }else{
       
        return _titleArray.count;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    if (tableView == self.tableView) {
        
        if (indexPath.section == 0) {
            return 60*Radio;
        }
        else if (indexPath.section == 1){
            
            if (indexPath.row == 0) {
                
                return 60*Radio;

            }else{
            
                return 70*Radio;
            }
        }
        else{
            
            return 150*Radio;
        }

    }else{
     
        return 50*Radio;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{

    if (tableView == self.tableView) {
        
        if (section == 0) {
            
            return 0.001f;
        }
        else if(section == 1){
            
            return 30*Radio;
            
        }else{
            
            return 25*Radio;
        }
        
    }else{
        
        return 0.001f;
    }

}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{

    return 0.001f;
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    if (tableView == self.tableView) {
        
        if (section == 0) {
            
            UIView *headView = nil;
            return headView;
            
        }else if(section == 1){
            
            UIView *headView = [[UIView alloc]init];
            headView.backgroundColor = RGB(247, 247, 247, 1);
            return headView;
            
        }else{
            
            UIView *headView = [[UIView alloc]init];
            headView.backgroundColor = RGB(247, 247, 247, 1);
            return headView;
        }
        
    }else{
        
        UIView *headView = nil;
        return headView;
    }

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    if (tableView == self.tableView) {
        
        UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
        if (indexPath.section == 0) {
            
            if (indexPath.row == 0) {
                
                self.headView.image = [UIImage imageNamed:@"user"];
                [cell addSubview:self.headView];
                [cell addSubview:self.teamName];
                _buton = [UIButton buttonWithType:UIButtonTypeCustom];
                _buton.tag = 100;
                [_buton setImage:[UIImage imageNamed:@"更多"] forState:UIControlStateNormal];
                _buton.frame = CGRectMake(Screen_Width-40, 20, 20, 20);
                [_buton addTarget:self action:@selector(showMoreButtonCliced:) forControlEvents:UIControlEventTouchUpInside];
                [_buton setEnlargeEdgeWithTop:30 right:20 bottom:20 left:20];
                [cell addSubview:_buton];
            }
            else if (indexPath.row == 1){
                
                [cell addSubview:self.productName];
                
            }else{
                
                UIView *varLine = [[UIView alloc]initWithFrame:CGRectMake(Screen_Width/2, 0, 1, 60*Radio)];
                varLine.backgroundColor = RGB(240, 240, 240, 1);
                [cell addSubview:varLine];
                
                UIView *bluViewL = [[UIView alloc]initWithFrame:CGRectMake(0, 10*Radio, 3*Radio, 15*Radio)];
                bluViewL.backgroundColor = RGB(43, 181, 238, 1);
                
                UIView *bluViewR = [[UIView alloc]initWithFrame:CGRectMake(Screen_Width/2+1, 10*Radio, 3*Radio, 15*Radio)];
                bluViewR.backgroundColor = RGB(43, 181, 238, 1);
                
                [cell addSubview:bluViewL];
                [cell addSubview:bluViewR];
                
                UILabel *sourceLabel = [[UILabel alloc]initWithFrame:CGRectMake(20*Radio, 10*Radio, 60, 15*Radio)];
                sourceLabel.textColor = RGB(151, 151, 151, 1);
                sourceLabel.font = [UIFont systemFontOfSize:FLEXIBLE(13)];
                sourceLabel.text = @"源语言";
                
                UILabel *targetLabel = [[UILabel alloc]initWithFrame:CGRectMake(Screen_Width/2+20*Radio, 10*Radio, 60, 15*Radio)];
                targetLabel.textColor = RGB(151, 151, 151, 1);
                targetLabel.font = [UIFont systemFontOfSize:FLEXIBLE(13)];
                targetLabel.text = @"目标语言";
                
                [cell addSubview:sourceLabel];
                [cell addSubview:targetLabel];
                
                _SLabel = [[UILabel alloc]initWithFrame:CGRectMake(20*Radio, 30*Radio, Screen_Width/2-30*Radio, 25*Radio)];
                _SLabel.textColor = RGB(65, 65, 65, 1);
                _SLabel.font = [UIFont systemFontOfSize:FLEXIBLE(15)];
                _SLabel.text = @"英文";
                
                _TLabel = [[UILabel alloc]initWithFrame:CGRectMake(Screen_Width/2+20*Radio, 30*Radio, Screen_Width/2-30*Radio, 25*Radio)];
                _TLabel.textColor = RGB(65, 65, 65, 1);
                _TLabel.font = [UIFont systemFontOfSize:FLEXIBLE(15)];
                _TLabel.text = @"简体中文";
                [cell addSubview:_SLabel];
                [cell addSubview:_TLabel];
                
                UIButton *selectLanguageL = [UIButton buttonWithType:UIButtonTypeCustom];
                [selectLanguageL setImage:[UIImage imageNamed:@"更多"] forState:UIControlStateNormal];
                selectLanguageL.frame = CGRectMake(Screen_Width/2-25*Radio, 40*Radio, 12, 12);
                [selectLanguageL addTarget:self action:@selector(selectlangugeResponds:) forControlEvents:UIControlEventTouchUpInside];
                selectLanguageL.tag = 500;
                [selectLanguageL setEnlargeEdgeWithTop:30 right:0 bottom:0 left:30];
                
                UIButton *selectLanguageR = [UIButton buttonWithType:UIButtonTypeCustom];
                [selectLanguageR setImage:[UIImage imageNamed:@"更多"] forState:UIControlStateNormal];
                selectLanguageR.frame = CGRectMake(Screen_Width-25*Radio, 40*Radio, 12, 12);
                [selectLanguageR addTarget:self action:@selector(selectlangugeResponds:) forControlEvents:UIControlEventTouchUpInside];
                selectLanguageR.tag = 600;
                [selectLanguageR setEnlargeEdgeWithTop:30 right:0 bottom:0 left:30];
                
                [cell addSubview:selectLanguageL];
                [cell addSubview:selectLanguageR];
            }
        }
        else if (indexPath.section == 1){
            
            if (indexPath.row == 0) {
                
                UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(20*Radio, 10*Radio, 100, 15*Radio)];
                title.textColor = RGB(151, 151, 151, 1);
                title.font = [UIFont systemFontOfSize:FLEXIBLE(13)];
                title.text = @"截止时间";
                [cell addSubview:title];
                
                UIImageView *dayView = [[UIImageView alloc]initWithFrame:CGRectMake(20*Radio, 35*Radio, 17*Radio, 17*Radio)];
                dayView.image = [UIImage imageNamed:@"时间-1"];
                [cell addSubview:dayView];
                
                _time = [[UILabel alloc]initWithFrame:CGRectMake(50*Radio, 33*Radio, 200*Radio, 20*Radio)];
                _time.textColor = RGB(111, 111, 111, 1);
                _time.font = [UIFont systemFontOfSize:FLEXIBLE(15)];
                NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
                formatter.dateFormat = @"yyyy年MM月dd日";
                NSString *dateString = [formatter stringFromDate:[NSDate date]];
                _time.text = [NSString stringWithFormat:@"%@ 18:00",dateString];
                [cell addSubview:_time];
                
                _buton = [UIButton buttonWithType:UIButtonTypeCustom];
                _buton.tag = 200;
                [_buton setImage:[UIImage imageNamed:@"更多"] forState:UIControlStateNormal];
                _buton.frame = CGRectMake(Screen_Width-40, 20, 20, 20);
                [_buton addTarget:self action:@selector(showMoreButtonCliced:) forControlEvents:UIControlEventTouchUpInside];
                [_buton setEnlargeEdgeWithTop:30 right:20 bottom:20 left:20];
                [cell addSubview:_buton];
                
            }
            else if (indexPath.row == 1){
                
                UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(20*Radio, 10*Radio, 100, 15*Radio)];
                title.textColor = RGB(151, 151, 151, 1);
                title.font = [UIFont systemFontOfSize:FLEXIBLE(13)];
                title.text = @"项目标签";
                [cell addSubview:title];
                
                _buton = [UIButton buttonWithType:UIButtonTypeCustom];
                _buton.tag = 300;
                [_buton setImage:[UIImage imageNamed:@"更多"] forState:UIControlStateNormal];
                _buton.frame = CGRectMake(Screen_Width-40, 20, 20, 20);
                [_buton addTarget:self action:@selector(showMoreButtonCliced:) forControlEvents:UIControlEventTouchUpInside];
                [_buton setEnlargeEdgeWithTop:30 right:20 bottom:20 left:20];
                [cell addSubview:_buton];
                
            }
            
        }
        else{
            
            UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(20*Radio, 10*Radio, 100, 15*Radio)];
            title.textColor = RGB(151, 151, 151, 1);
            title.font = [UIFont systemFontOfSize:FLEXIBLE(13)];
            title.text = @"项目备注";
            [cell addSubview:title];
            
            _remarkTextView = [[UITextView alloc]initWithFrame:CGRectMake(20*Radio, 30*Radio, Screen_Width-20*Radio*2, 110*Radio)];
            _remarkTextView.backgroundColor = [UIColor whiteColor];
            _remarkTextView.textAlignment = NSTextAlignmentLeft;
            _remarkTextView.font = [UIFont systemFontOfSize:FLEXIBLE(14)];
            _remarkTextView.textColor = [UIColor lightGrayColor];
            _remarkTextView.layer.borderColor = RGB(240, 240, 240, 1).CGColor;
            _remarkTextView.layer.borderWidth = 1.f;
            _remarkTextView.delegate = self;
            self.automaticallyAdjustsScrollViewInsets = NO;
            _textViewPlaceholderLabelF = [[UILabel alloc] initWithFrame:CGRectMake(10, 7, 150, 20)];
            _textViewPlaceholderLabelF.text = @"请填写项目描述信息";
            _textViewPlaceholderLabelF.textColor = RGB(180, 180, 180, 1);
            _textViewPlaceholderLabelF.font = [UIFont systemFontOfSize:FLEXIBLE(14)];
            [_remarkTextView addSubview:_textViewPlaceholderLabelF];
            [cell addSubview:_remarkTextView];
            
            _wordCount = [[UILabel alloc]initWithFrame:CGRectMake(Screen_Width-20*Radio*2-35*Radio, 110*Radio-20*Radio, 35*Radio, 20*Radio)];
            _wordCount.textColor = [UIColor lightGrayColor];
            _wordCount.font = [UIFont systemFontOfSize:FLEXIBLE(11)];
            _wordCount.text = @"0/50";
            [_remarkTextView addSubview:_wordCount];
        }
        
        if (indexPath.section == 2) {
            
            _line = [[UIView alloc]initWithFrame:CGRectMake(0, 149*Radio, Screen_Width, 1)];
            _line.backgroundColor = RGB(247, 247, 247, 1);
            [cell addSubview:_line];
            
        }else{
            
            if (indexPath.row == 1 && indexPath.section == 1) {
                
                _line = [[UIView alloc]initWithFrame:CGRectMake(0, 69*Radio, Screen_Width, 1)];
                _line.backgroundColor = RGB(247, 247, 247, 1);
                [cell addSubview:_line];
                
            }else{
            
                _line = [[UIView alloc]initWithFrame:CGRectMake(0, 59*Radio, Screen_Width, 1)];
                _line.backgroundColor = RGB(247, 247, 247, 1);
                [cell addSubview:_line];

            }
        }
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
        
    }else{

        YZSortCell *cell = [tableView dequeueReusableCellWithIdentifier:IDR];
        cell.textLabel.text = _titleArray[indexPath.row];
        cell.textLabel.font = [UIFont systemFontOfSize:FLEXIBLE(15)];
        
        return cell;
    }

}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (tableView == self.tableView) {
        if (indexPath.section == 0 && indexPath.row == 0) {
            self.coverView.frame = CGRectMake(0, 64, Screen_Width, 0);
            [UIView animateWithDuration:0.3 animations:^{
                
                CGRect frame = CGRectMake(0, 60*Radio, Screen_Width, 0);
                self.tableView_team.frame = frame;
                
            } completion:^(BOOL finished) {
                
            }];
        }
    }else{
        _selectedCol = indexPath.row;
        _teamName.text = _titleArray[indexPath.row];
        self.teamName.text = _titleArray[_selectedCol];
        [self.headView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",headImageViewOSS,_faceArray[_selectedCol]]] placeholderImage:[UIImage imageNamed:@"user"]];

        self.coverView.frame = CGRectMake(0, 64, Screen_Width, 0);
        [UIView animateWithDuration:0.3 animations:^{
            
            CGRect frame = CGRectMake(0, 60*Radio, Screen_Width, 0);
            self.tableView_team.frame = frame;
            
        } completion:^(BOOL finished) {
            
        }];

    }
}


#pragma mark -- Event
- (void)showMoreButtonCliced:(UIButton *)sender{

    sender.enabled = NO;
    
    if (sender.tag == 100) {

        [self.tableView_team reloadData];
        self.teamName.text = _titleArray[_selectedCol];
        [self.headView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",headImageViewOSS,_faceArray[_selectedCol]]] placeholderImage:[UIImage imageNamed:@"user"]];

        NSIndexPath *indexPath = [NSIndexPath indexPathForItem:_selectedCol inSection:0];
        [self.tableView_team selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
        self.coverView.frame = CGRectMake(0, 60*Radio, Screen_Width, Screen_Height-64-60*Radio);
        
        [UIView animateWithDuration:0.3 animations:^{
            
            CGRect frame = CGRectMake(0, 60*Radio, Screen_Width, _titleArray.count*50*Radio);
            self.tableView_team.frame = frame;
            
        } completion:^(BOOL finished) {
            
        }];

        
    }else if (sender.tag == 200){
    
        YHXCalendarView *view = [[YHXCalendarView alloc]initWithFrame:CGRectMake(0, Screen_Height, Screen_Width, 0)];
        [self.view addSubview:view];
        
        [UIView animateWithDuration:0.3 animations:^{
            
            CGRect frame = CGRectMake(0, 61, Screen_Width, Screen_Height-125);
            view.frame = frame;
            self.coverView.frame = CGRectMake(0, 0, Screen_Width, 100);
            
        } completion:^(BOOL finished) {
            
        }];
        
    }else if (sender.tag == 300){
        
        [UIView animateWithDuration:0.3 animations:^{
            
            CGRect frame = CGRectMake(0, 61, Screen_Width, Screen_Height-125);
            _tagsView.frame = frame;
            self.coverView.frame = CGRectMake(0, 0, Screen_Width, 100);
            
        } completion:^(BOOL finished) {
            
        }];
    }
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        sender.enabled = YES;
    });
}

- (void)selectlangugeResponds:(UIButton *)sender{

    SelectLangViewController *vc = [[SelectLangViewController alloc]init];
    vc.didSelectSectionHandler = ^(NSString *type){
        if (sender.tag == 500) {
            _SLabel.text = type;
        }else{
            _TLabel.text = type;
        }
    };
    [self presentViewController:vc animated:YES completion:nil];

}

- (void)delateTagsCliced:(UIButton *)sender{

    [_tagLabel removeFromSuperview];
    [_tagLabeltwo removeFromSuperview];
    [_tagLabelThr removeFromSuperview];
    switch (sender.tag) {
        case 800:
        {
            [[NSNotificationCenter defaultCenter]postNotificationName:@"delateTag" object:_tags[0]];
            [_tags removeObjectAtIndex:0];
            UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:1]];
            [self creatBaseLabelsOnCell:cell WithLabels:_tags];
        }
            break;
        case 850:
        {
            [[NSNotificationCenter defaultCenter]postNotificationName:@"delateTag" object:_tags[1]];
            [_tags removeObjectAtIndex:1];
            UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:1]];
            [self creatBaseLabelsOnCell:cell WithLabels:_tags];
        }
            break;
        case 900:
        {
            [[NSNotificationCenter defaultCenter]postNotificationName:@"delateTag" object:_tags[2]];
            [_tags removeObjectAtIndex:2];
            UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:1]];
            [self creatBaseLabelsOnCell:cell WithLabels:_tags];
        }
            break;
        default:
            break;
    }
}

- (void)SureButtonCliced:(UIButton *)sender{
    
    sender.enabled = NO;
    //获取语言对
    [_languageArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
       
        if ([obj[@"dictionaryValue"] isEqualToString:_SLabel.text]) {
            _sourceKey = _languageArray[idx][@"dictionaryKey"];
        }
        else if ([obj[@"dictionaryValue"] isEqualToString:_TLabel.text]){
            _targetKey = _languageArray[idx][@"dictionaryKey"];
        }
    }];
    
    //获取团队Id
    [_titleArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
       
        if ([obj isEqualToString:_teamName.text]) {
            _ownerId = _idArray[idx];
        }
    }];
    
    //获取标签组
    NSMutableArray *endTags = [NSMutableArray array];
    [_tagArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
       
        if ([_tagLabel.text isEqualToString:[NSString stringWithFormat:@"  %@",obj[@"labelName"]]]) {
            [endTags addObject:[NSString stringWithFormat:@"%@_%@",obj[@"labelId"],obj[@"labelName"]]];
        }
        if ([_tagLabeltwo.text isEqualToString:[NSString stringWithFormat:@"  %@",obj[@"labelName"]]]) {
            [endTags addObject:[NSString stringWithFormat:@"%@_%@",obj[@"labelId"],obj[@"labelName"]]];
        }
        if ([_tagLabelThr.text isEqualToString:[NSString stringWithFormat:@"  %@",obj[@"labelName"]]]) {
            [endTags addObject:[NSString stringWithFormat:@"%@_%@",obj[@"labelId"],obj[@"labelName"]]];
        }
    }];
    
    NSString *labelStr = [endTags componentsJoinedByString:@","];
    NSLog(@"endStr = %@",labelStr);
    
    NSDictionary *param = @{@"ownerId":_ownerId,
                            @"projectName":_productName.text,
                            @"sourcelangkey":_sourceKey,
                            @"targetlangkey":_targetKey,
                            @"deallineTime":_time.text,
                            @"remark":_remarkTextView.text,
                            @"fields":labelStr};
    NSLog(@"param ------- %@",param);
    //创建项目
    [AvailableNetWorking postWithUrl:CreateNewProject_connector params:param successHandler:^(id responseObject) {
        
        NSLog(@"===%@",responseObject);
        NSLog(@"===%@",responseObject[@"message"]);

        if ([responseObject[@"code"] integerValue] == 200) {
            
            sender.enabled = YES;
            UploadSetViewController *vc = [[UploadSetViewController alloc]init];
            vc.projectId = [NSString stringWithFormat:@"%@",responseObject[@"result"][@"project_id"]];
            vc.sourcelangkey = _sourceKey;
            [self.navigationController pushViewController:vc animated:YES];
        }else{
            [TopAlertView SetUpbackgroundColor:AlertRedColor andStayTime:2.0 andImageName:@"imagePlaceholder" andTitleStr:responseObject[@"message"] andTitleColor:[UIColor whiteColor] andCancel:YES];
        }
        
    } falureHandler:^(NSError *error) {
            [TopAlertView SetUpbackgroundColor:AlertRedColor andStayTime:2.0 andImageName:@"imagePlaceholder" andTitleStr:@"新建项目失败" andTitleColor:[UIColor whiteColor] andCancel:YES];
    }];
    
}

#pragma mark -- UItextViewDelegate

- (void)textViewDidChange:(UITextView *)textView{

    NSInteger count = [textView.text length];
    _wordCount.text = [NSString stringWithFormat:@"%ld/50",(long)count];
}


//设置textView的placeholder
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    if (textView == _remarkTextView) {
        //[text isEqualToString:@""] 表示输入的是退格键
        if (![text isEqualToString:@""])
        {
            _textViewPlaceholderLabelF.hidden = YES;
            _productName.textColor = [UIColor blackColor];
        }
        
        //range.location == 0 && range.length == 1 表示输入的是第一个字符
        if ([text isEqualToString:@""] && range.location == 0 && range.length == 1)
            
        {
            _textViewPlaceholderLabelF.hidden = NO;
        }
        return YES;

    }
    else{
        //[text isEqualToString:@""] 表示输入的是退格键
        if (![text isEqualToString:@""])
        {
            _textViewPlaceholderLabel.hidden = YES;
            _productName.textColor = [UIColor blackColor];
        }
        
        //range.location == 0 && range.length == 1 表示输入的是第一个字符
        if ([text isEqualToString:@""] && range.location == 0 && range.length == 1)
            
        {
            _textViewPlaceholderLabel.hidden = NO;
        }
        return YES;

    }
}

#pragma mark -- textView文字垂直居中处理
- (void)contentSizeToFitWithTextView:(UITextView *)textView
{
    //先判断一下有没有文字（没文字就没必要设置居中了）
    if([textView.text length]>0)
    {
        //textView的contentSize属性
        CGSize contentSize = textView.contentSize;
        //textView的内边距属性
        UIEdgeInsets offset;
        CGSize newSize = contentSize;
        
        //如果文字内容高度没有超过textView的高度
        if(contentSize.height <= textView.frame.size.height)
        {
            //textView的高度减去文字高度除以2就是Y方向的偏移量，也就是textView的上内边距
            CGFloat offsetY = (textView.frame.size.height - contentSize.height)/2;
            offset = UIEdgeInsetsMake(offsetY, 0, 0, 0);
        }
        else          //如果文字高度超出textView的高度
        {
            newSize = textView.frame.size;
            offset = UIEdgeInsetsZero;
            CGFloat fontSize = 18;
            
            //通过一个while循环，设置textView的文字大小，使内容不超过整个textView的高度（这个根据需要可以自己设置）
            while (contentSize.height > textView.frame.size.height)
            {
                [textView setFont:[UIFont fontWithName:@"Helvetica Neue" size:fontSize--]];
                contentSize = textView.contentSize;
            }
            newSize = contentSize;
        }
        
        //根据前面计算设置textView的ContentSize和Y方向偏移量
        [textView setContentSize:newSize];
        [textView setContentInset:offset];
        
    }
}

#pragma mark -- notification

- (void)hideCoverCliced:(NSNotification *)notification{
    
    NSLog(@"notification.object --- %@",notification.object);
    _time.text = [NSString stringWithFormat:@"%@",notification.object];
    
    [UIView animateWithDuration:0.3 animations:^{
        
        self.coverView.frame = CGRectMake(0, 0, Screen_Width, 0);
        
    } completion:^(BOOL finished) {
        
    }];
}

- (void)dismissTagsViewRespond{

    for (NSString *str in _tags) {
        NSLog(@"tag ===== %@",str);
    }
    [_tagLabel removeFromSuperview];
    [_tagLabeltwo removeFromSuperview];
    [_tagLabelThr removeFromSuperview];
    UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:1]];
    [self creatBaseLabelsOnCell:cell WithLabels:_tags];
    
    [UIView animateWithDuration:0.25 animations:^{
        
        CGRect frame = CGRectMake(0, Screen_Height, Screen_Width, 0);
        _tagsView.frame = frame;
        self.coverView.frame = CGRectMake(0, 0, Screen_Width, 0);
        
    } completion:^(BOOL finished) {
        
    }];

}


- (void)creatBaseLabelsOnCell:(UIView *)cell WithLabels:(NSArray *)labels{

    _tagLabel = [[UILabel alloc]initWithFrame:CGRectMake(20*Radio, 35*Radio, 50*Radio, 20*Radio)];
    _tagLabel.backgroundColor = RGB(39, 181, 238, 1);
    _tagLabel.textColor = [UIColor whiteColor];
    _tagLabel.textAlignment = NSTextAlignmentLeft;
    _tagLabel.font = [UIFont systemFontOfSize:FLEXIBLE(13)];
    _tagLabel.layer.cornerRadius = 10*Radio;
    _tagLabel.layer.masksToBounds = YES;
    _tagLabel.layer.shouldRasterize = YES; //圆角缓存
    _tagLabel.layer.rasterizationScale = [UIScreen mainScreen].scale;//提高流畅度
    [_tagLabel setUserInteractionEnabled:YES];
    [cell addSubview:_tagLabel];
    
    _tagLabeltwo = [[UILabel alloc]initWithFrame:CGRectMake(_tagLabel.frame.origin.x+_tagLabel.frame.size.width+20*Radio, 35*Radio, 50*Radio, 20*Radio)];
    _tagLabeltwo.backgroundColor = RGB(39, 181, 238, 1);
    _tagLabeltwo.textColor = [UIColor whiteColor];
    _tagLabeltwo.textAlignment = NSTextAlignmentLeft;
    _tagLabeltwo.font = [UIFont systemFontOfSize:FLEXIBLE(13)];
    _tagLabeltwo.layer.cornerRadius = 10*Radio;
    _tagLabeltwo.layer.masksToBounds = YES;
    _tagLabeltwo.layer.shouldRasterize = YES; //圆角缓存
    _tagLabeltwo.layer.rasterizationScale = [UIScreen mainScreen].scale;//提高流畅度
    [_tagLabeltwo setUserInteractionEnabled:YES];
    [cell addSubview:_tagLabeltwo];
    
    _tagLabelThr = [[UILabel alloc]initWithFrame:CGRectMake(_tagLabeltwo.frame.origin.x+_tagLabeltwo.frame.size.width+20*Radio, 35*Radio, 50*Radio, 20*Radio)];
    _tagLabelThr.backgroundColor = RGB(39, 181, 238, 1);
    _tagLabelThr.textColor = [UIColor whiteColor];
    _tagLabelThr.textAlignment = NSTextAlignmentLeft;
    _tagLabelThr.font = [UIFont systemFontOfSize:FLEXIBLE(13)];
    _tagLabelThr.layer.cornerRadius = 10*Radio;
    _tagLabelThr.layer.masksToBounds = YES;
    _tagLabelThr.layer.shouldRasterize = YES; //圆角缓存
    _tagLabelThr.layer.rasterizationScale = [UIScreen mainScreen].scale;//提高流畅度
    [_tagLabelThr setUserInteractionEnabled:YES];
    [cell addSubview:_tagLabelThr];
    
    NSArray *types = labels;
    NSInteger index = types.count;
    if (index == 3) {
        _tagLabel.text       = types[0];
        _tagLabeltwo.text    = types[1];
        _tagLabelThr.text    = types[2];
    }
    else if (index == 2){
        _tagLabel.text       = types[0];
        _tagLabeltwo.text    = types[1];
        [_tagLabelThr removeFromSuperview];
    }
    else if (index == 1){
        _tagLabel.text       = types[0];
        [_tagLabeltwo removeFromSuperview];
        [_tagLabelThr removeFromSuperview];
        
    }
    else{
        
        [_tagLabel removeFromSuperview];
        [_tagLabeltwo removeFromSuperview];
        [_tagLabelThr removeFromSuperview];
    }
    
    if (types.count == 0 || [types[0] isEqualToString:@""]) {
        [_tagLabel removeFromSuperview];
    }
    
    if (types.count > 0) {
        CGSize size = [[NSString stringWithFormat:@"%@****",types[0]] sizeWithAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:FLEXIBLE(13)]}];
        CGSize sizeNew = CGSizeMake(ceilf(size.width), ceilf(size.height));
        _tagLabel.frame = CGRectMake(20*Radio, 35*Radio, sizeNew.width, 20*Radio);
    }
    if (types.count > 1) {
        CGSize sizetwo = [[NSString stringWithFormat:@"%@****",types[1]] sizeWithAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:FLEXIBLE(13)]}];
        CGSize sizeNewtwo = CGSizeMake(ceilf(sizetwo.width), ceilf(sizetwo.height));
        _tagLabeltwo.frame = CGRectMake(_tagLabel.frame.origin.x+_tagLabel.frame.size.width+10*Radio, 35*Radio, sizeNewtwo.width, 20*Radio);
    }
    if (types.count > 2) {
        CGSize sizethr = [[NSString stringWithFormat:@"%@****",types[2]] sizeWithAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:FLEXIBLE(13)]}];
        CGSize sizeNewthr = CGSizeMake(ceilf(sizethr.width), ceilf(sizethr.height));
        _tagLabelThr.frame = CGRectMake(_tagLabeltwo.frame.origin.x+_tagLabeltwo.frame.size.width+10*Radio, 35*Radio, sizeNewthr.width, 20*Radio);
    }
    
    _deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _deleteButton.tag = 800;
    [_deleteButton setImage:[UIImage imageNamed:@"取消"] forState:UIControlStateNormal];
    _deleteButton.frame = CGRectMake(_tagLabel.frame.size.width-25*Radio, 0, 20*Radio, 20*Radio);
    [_deleteButton addTarget:self action:@selector(delateTagsCliced:) forControlEvents:UIControlEventTouchUpInside];
    [_deleteButton setEnlargeEdgeWithTop:5 right:5 bottom:5 left:10];
    [_tagLabel addSubview:_deleteButton];
    
    _deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _deleteButton.tag = 850;
    [_deleteButton setImage:[UIImage imageNamed:@"取消"] forState:UIControlStateNormal];
    _deleteButton.frame = CGRectMake(_tagLabeltwo.frame.size.width-25*Radio, 0, 20*Radio, 20*Radio);
    [_deleteButton addTarget:self action:@selector(delateTagsCliced:) forControlEvents:UIControlEventTouchUpInside];
    [_deleteButton setEnlargeEdgeWithTop:5 right:5 bottom:5 left:10];
    [_tagLabeltwo addSubview:_deleteButton];
    
    _deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _deleteButton.tag = 900;
    [_deleteButton setImage:[UIImage imageNamed:@"取消"] forState:UIControlStateNormal];
    _deleteButton.frame = CGRectMake(_tagLabelThr.frame.size.width-25*Radio, 0, 20*Radio, 20*Radio);
    [_deleteButton addTarget:self action:@selector(delateTagsCliced:) forControlEvents:UIControlEventTouchUpInside];
    [_deleteButton setEnlargeEdgeWithTop:5 right:5 bottom:5 left:10];
    [_tagLabelThr addSubview:_deleteButton];


}

#pragma mark -- 解析json
- (id)toArrayOrNSDictionary:(NSData *)jsonData{
    
    NSError *error = nil;
    id jsonObject = [NSJSONSerialization JSONObjectWithData:jsonData
                                                    options:NSJSONReadingAllowFragments
                                                      error:nil];
    
    if (jsonObject != nil && error == nil){
        return jsonObject;
    }else{
        // 解析错误
        return nil;
    }
    
}


#pragma mark -- getter
- (UITableView *)tableView{
    
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, Screen_Width, Screen_Height-64 - 50*Radio) style:UITableViewStyleGrouped];
        _tableView.backgroundColor = RGB(247, 247, 247, 1);
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.separatorColor = [UIColor clearColor];
    }
    return _tableView;
}

- (UIImageView *)headView{

    if (!_headView) {
        _headView = [[UIImageView alloc]initWithFrame:CGRectMake(20*Radio, 30*Radio-25*Radio/2, 25*Radio, 25*Radio)];
        _headView.layer.cornerRadius = 25*Radio/2;
        _headView.layer.masksToBounds = YES;
    }
    return _headView;
}

- (UILabel *)teamName{

    if (!_teamName) {
        _teamName = [[UILabel alloc]initWithFrame:CGRectMake(55*Radio, 15*Radio, Screen_Width - 100*Radio-20, 30*Radio)];
        _teamName.backgroundColor = [UIColor clearColor];
        _teamName.textColor = [UIColor blackColor];
        _teamName.font = [UIFont systemFontOfSize:FLEXIBLE(17)];
        _teamName.text = @"正在加载...";
    }
    return _teamName;
}

- (UITextView *)productName{

    if (!_productName) {
        _productName = [[UITextView alloc]initWithFrame:CGRectMake(15*Radio, 0, Screen_Width-15*Radio, 60*Radio)];
        _productName.delegate = self;
        _productName.scrollEnabled = YES;
        _productName.editable = YES;
        _productName.textColor = RGB(180, 180, 180, 1);
        _productName.backgroundColor = [UIColor clearColor];
        _productName.font = [UIFont systemFontOfSize:FLEXIBLE(16)];
        _productName.text = @" ";
        _textViewPlaceholderLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 7, 150, 20)];
        _textViewPlaceholderLabel.text = @"输入项目名称";
        _textViewPlaceholderLabel.textColor = RGB(180, 180, 180, 1);
        _textViewPlaceholderLabel.font = [UIFont systemFontOfSize:FLEXIBLE(16)];
        [_productName addSubview:_textViewPlaceholderLabel];
    }
    return _productName;
}

- (UIButton *)sureButton{

    if (!_sureButton) {
        
        _sureButton = [UIButton buttonWithType:UIButtonTypeSystem];
        _sureButton.frame = CGRectMake(0, Screen_Height - 50*Radio - 64, Screen_Width, 50*Radio);
        _sureButton.backgroundColor = RGB(57, 186, 241, 1);
        [_sureButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_sureButton setTitle:@"确定" forState:UIControlStateNormal];
        [_sureButton addTarget:self action:@selector(SureButtonCliced:) forControlEvents:UIControlEventTouchUpInside];
        _sureButton.titleLabel.font = [UIFont systemFontOfSize:FLEXIBLE(18)];
    }
    return _sureButton;
}

- (UIView *)coverView{
    
    if (!_coverView) {
        _coverView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_Width, 0)];
        _coverView.backgroundColor = RGB(0, 0, 0, 0.4);
    }
    return _coverView;
}

- (UITableView *)tableView_team{
    
    if (!_tableView_team) {
        _tableView_team = [[UITableView alloc]initWithFrame:CGRectMake(0, 60*Radio, Screen_Width, 0) style:UITableViewStylePlain];
        _tableView_team.backgroundColor = RGB(247, 247, 247, 1);
        _tableView_team.dataSource = self;
        _tableView_team.delegate = self;
        _tableView_team.separatorColor = [UIColor clearColor];
    }
    return _tableView_team;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

@end
